<?php

/**
 * @Author: wuchenge
 * @Date:   2022-04-19 14:33:53
 * @Email: ligui0506@126.com
 * @Descript:
 */
namespace App\Libraries;

class Utils
{
    /**
     * 模型设置图片
     * @param [type] $image [description]
     */
    public static function setImage($image)
    {
        $url    = config('filesystems.disks.qiniu.domains.default');
        $values = ltrim(str_replace($url, '', $image), '/');

        return $values;
    }

    /**
     * 获取模型图片
     * @param  [type] $image [description]
     * @return [type]        [description]
     */
    public static function getImage($image)
    {
        return config('filesystems.disks.qiniu.domains.default') . $image;
    }

    /**
     * 生成随机字母加数字 字符串
     * @param int $len
     * @param null $chars
     * @return string
     */
    public static function getRandomString($len = 6, $type = 2)
    {
        $cs = ["abcdefghijklmnopqrstuvwxyz", 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', "123456789"];

        switch ($type) {
            case 1:
                $chars = $cs[0];
                break;
            case 2:
                $chars = $cs[1];
                break;
            case 3:
                $chars = $cs[2];
                break;
            case 4:
                $chars = $cs[1] . $cs[2];
                break;
            default:
                $chars = $cs[0] . $cs[1] . $cs[2];
        }
        mt_srand(10000000 * (double) microtime());
        for ($i = 0, $str = '', $lc = strlen($chars) - 1; $i < $len; $i++) {
            $str .= $chars[mt_rand(0, $lc)];
        }
        return $str;
    }
}
